﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////


#include "CommandParameters.h"
#include "ComponentEditorGnufUICmdRegisterHelper.h"
#include "ComponentEditorGnufUICommandIds.h"
#include "ComponentEditorConfigTool.h"
#include "FilePath.h"
#include "GbmpFileSystem.h"
#include "GcmpInternalCommandNames.h"
#include "ICommandManager.h"
#include "OpenLocalFamilyDocumentFromSampleCommand.h"
#include "UiCommonDialog.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;
using namespace gfam;

REGISTER_FAM_GNUF_UI_COMMAND(OpenLocalFamilyDocumentFromSampleCommand)

OpenLocalFamilyDocumentFromSampleCommand::OpenLocalFamilyDocumentFromSampleCommand()
    : CommandBase(OPEN_LOCAL_FAMILY_DOCUMENT_FROM_SAMPLE_COMMAND)
{}

gcmp::OwnerPtr<gcmp::IAction> OpenLocalFamilyDocumentFromSampleCommand::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    gcmp::ICommandManager* pCommandManager = gcmp::ICommandManager::Get();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pCommandManager, L"pCommandManager为空指针", L"paramodel", L"2024-02-20")
    pCommandManager->SendCommand(ID_CMD_COMPONENT_EDITOR_OPEN_FILE_BY_TEMPORARY_COPY, cmdParams);

    return nullptr;
}

REGISTER_FAM_GNUF_UI_COMMAND(OpenLocalFamilyDocumentFromGapSampleCommand)
REGISTER_FAM_GNUF_UI_COMMAND(OpenLocalFamilyDocumentFromGstSampleCommand)
REGISTER_FAM_GNUF_UI_COMMAND(OpenLocalFamilyDocumentFromGMepSampleCommand)
REGISTER_FAM_GNUF_UI_COMMAND(OpenLocalFamilyDocumentFromBIMMAKESampleCommand)
REGISTER_FAM_GNUF_UI_COMMAND(OpenLocalFamilyDocumentFromGroadSampleCommand)
REGISTER_FAM_GNUF_UI_COMMAND(OpenLocalFamilyDocumentFromOtherSampleCommand)

// Gap Sample
OpenLocalFamilyDocumentFromGapSampleCommand::OpenLocalFamilyDocumentFromGapSampleCommand()
    : CommandBase(OPEN_LOCAL_FAMILY_DOCUMENT_FROM_GAP_SAMPLE_COMMAND)
{}

gcmp::OwnerPtr<gcmp::IAction> OpenLocalFamilyDocumentFromGapSampleCommand::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    // 获取路径
    std::wstring productConfigPath = ComponentEditorConfigTool::GetSpecifyProductConfigPath(L"AppParamodel");
    if (productConfigPath.empty())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }
    std::wstring productFamilyParametersFilePath = FilePath::Combine(productConfigPath, L"Samples", L"双扇推拉门双亮子.gac");
    FileInfo info(productFamilyParametersFilePath);
    if (!info.Exists())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }

    CommandParameters newCmdParams;
    newCmdParams[L"FilePath"] = productFamilyParametersFilePath;
    gcmp::ICommandManager* pCommandManager = gcmp::ICommandManager::Get();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pCommandManager, L"pCommandManager为空指针", L"paramodel", L"2024-02-20");
    pCommandManager->SendCommand(ID_CMD_COMPONENT_EDITOR_OPEN_FILE_BY_TEMPORARY_COPY, newCmdParams);

    return nullptr;
}

// Gst Sample
OpenLocalFamilyDocumentFromGstSampleCommand::OpenLocalFamilyDocumentFromGstSampleCommand()
    : CommandBase(OPEN_LOCAL_FAMILY_DOCUMENT_FROM_GST_SAMPLE_COMMAND)
{}

gcmp::OwnerPtr<gcmp::IAction> OpenLocalFamilyDocumentFromGstSampleCommand::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    // 获取路径
    std::wstring productConfigPath = ComponentEditorConfigTool::GetSpecifyProductConfigPath(L"AppParamodel");
    if (productConfigPath.empty())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }
    std::wstring productFamilyParametersFilePath = FilePath::Combine(productConfigPath, L"Samples", L"H型钢柱.gac");
    FileInfo info(productFamilyParametersFilePath);
    if (!info.Exists())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }

    CommandParameters newCmdParams;
    newCmdParams[L"FilePath"] = productFamilyParametersFilePath;
    gcmp::ICommandManager* pCommandManager = gcmp::ICommandManager::Get();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pCommandManager, L"pCommandManager为空指针", L"paramodel", L"2024-02-20")
    pCommandManager->SendCommand(ID_CMD_COMPONENT_EDITOR_OPEN_FILE_BY_TEMPORARY_COPY, newCmdParams);

    return nullptr;
}

// GMep Sample
OpenLocalFamilyDocumentFromGMepSampleCommand::OpenLocalFamilyDocumentFromGMepSampleCommand()
    : CommandBase(OPEN_LOCAL_FAMILY_DOCUMENT_FROM_GMEP_SAMPLE_COMMAND)
{}

gcmp::OwnerPtr<gcmp::IAction> OpenLocalFamilyDocumentFromGMepSampleCommand::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    // 获取路径
    std::wstring productConfigPath = ComponentEditorConfigTool::GetSpecifyProductConfigPath(L"AppParamodel");
    if (productConfigPath.empty())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }
    std::wstring productFamilyParametersFilePath = FilePath::Combine(productConfigPath, L"Samples", L"压差旁通平衡阀.gac");
    FileInfo info(productFamilyParametersFilePath);
    if (!info.Exists())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }

    CommandParameters newCmdParams;
    newCmdParams[L"FilePath"] = productFamilyParametersFilePath;
    gcmp::ICommandManager* pCommandManager = gcmp::ICommandManager::Get();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pCommandManager, L"pCommandManager为空指针", L"paramodel", L"2024-02-20");
    pCommandManager->SendCommand(ID_CMD_COMPONENT_EDITOR_OPEN_FILE_BY_TEMPORARY_COPY, newCmdParams);

    return nullptr;
}

// BIMMAKE Sample
OpenLocalFamilyDocumentFromBIMMAKESampleCommand::OpenLocalFamilyDocumentFromBIMMAKESampleCommand()
    : CommandBase(OPEN_LOCAL_FAMILY_DOCUMENT_FROM_BIMMAKE_SAMPLE_COMMAND)
{}

gcmp::OwnerPtr<gcmp::IAction> OpenLocalFamilyDocumentFromBIMMAKESampleCommand::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    // 获取路径
    std::wstring productConfigPath = ComponentEditorConfigTool::GetSpecifyProductConfigPath(L"AppParamodel");
    if (productConfigPath.empty())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }
    std::wstring productFamilyParametersFilePath = FilePath::Combine(productConfigPath, L"Samples", L"门卫岗亭.gac");
    FileInfo info(productFamilyParametersFilePath);
    if (!info.Exists())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }

    CommandParameters newCmdParams;
    newCmdParams[L"FilePath"] = productFamilyParametersFilePath;
    gcmp::ICommandManager::Get()->SendCommand(ID_CMD_COMPONENT_EDITOR_OPEN_FILE_BY_TEMPORARY_COPY, newCmdParams);

    return nullptr;
}

// Groad Sample
OpenLocalFamilyDocumentFromGroadSampleCommand::OpenLocalFamilyDocumentFromGroadSampleCommand()
    : CommandBase(OPEN_LOCAL_FAMILY_DOCUMENT_FROM_GROAD_SAMPLE_COMMAND)
{}

gcmp::OwnerPtr<gcmp::IAction> OpenLocalFamilyDocumentFromGroadSampleCommand::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    // 获取路径
    std::wstring productConfigPath = ComponentEditorConfigTool::GetSpecifyProductConfigPath(L"AppParamodel");
    if (productConfigPath.empty())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }
    std::wstring productFamilyParametersFilePath = FilePath::Combine(productConfigPath, L"Samples", L"桥墩.gac");
    FileInfo info(productFamilyParametersFilePath);
    if (!info.Exists())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }

    CommandParameters newCmdParams;
    newCmdParams[L"FilePath"] = productFamilyParametersFilePath;
    gcmp::ICommandManager* pCommandManager = gcmp::ICommandManager::Get();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pCommandManager, L"pCommandManager为空指针", L"paramodel", L"2024-02-20");
    pCommandManager->SendCommand(ID_CMD_COMPONENT_EDITOR_OPEN_FILE_BY_TEMPORARY_COPY, newCmdParams);

    return nullptr;
}

// Other Sample
OpenLocalFamilyDocumentFromOtherSampleCommand::OpenLocalFamilyDocumentFromOtherSampleCommand()
    : CommandBase(OPEN_LOCAL_FAMILY_DOCUMENT_FROM_OTHER_SAMPLE_COMMAND)
{}

gcmp::OwnerPtr<gcmp::IAction> OpenLocalFamilyDocumentFromOtherSampleCommand::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    // 获取路径
    std::wstring productConfigPath = ComponentEditorConfigTool::GetSpecifyProductConfigPath(L"AppParamodel");
    if (productConfigPath.empty())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }
    std::wstring productFamilyParametersFilePath = FilePath::Combine(productConfigPath, L"Samples", L"自卸车.gac");
    FileInfo info(productFamilyParametersFilePath);
    if (!info.Exists())
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"文件不存在"), GBMP_TR(L"未找到示例文件！"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }

    CommandParameters newCmdParams;
    newCmdParams[L"FilePath"] = productFamilyParametersFilePath;
    gcmp::ICommandManager* pCommandManager = gcmp::ICommandManager::Get();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pCommandManager, L"pCommandManager为空指针", L"paramodel", L"2024-02-20");
    pCommandManager->SendCommand(ID_CMD_COMPONENT_EDITOR_OPEN_FILE_BY_TEMPORARY_COPY, newCmdParams);

    return nullptr;
}